package com.example.boot3.service.Impl;

import com.example.boot3.mapper.UseMapper;
import com.example.boot3.mapper.VehicleMapper;
import com.example.boot3.model.Use;
import com.example.boot3.service.UseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;

@Service
public class UseServiceImpl implements UseService {
    @Autowired
    private UseMapper useMapper;
    @Autowired
    private VehicleMapper vehicleMapper;


    @Override
    public List<Use> getUseList() {
        return useMapper.getUseList();
    }

    @Override
    public Integer applyVehicle(Use use) {
        /** 待完善逻辑~ */
        /** 1代表成功，2代表正在出车，3代表正在维修 */
        try{
            /**  查询该车现在的状态 */
            String status = vehicleMapper.getVehicleStatus(use.getVehicle_id());
            System.out.println(status);
            if(status.equals("出车")){
                return 2;

            } else if (status.equals("维修")) {
                return 3;
            }
            useMapper.applyVehicle(use);
            vehicleMapper.updateVehicleStatus(use.getVehicle_id(),"出车");
            return 1;
        }
        catch (Exception e){
            System.out.println(e.getMessage());
            return 0;
        }


    }


    @Override
    public List<Map<String, String>> getFleetUseList() {
        return useMapper.getFleetUseList();
    }
}
